package com.ruoyi.web.controller.biz;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.biz.model.req.ReceiptProjectReq;
import com.ruoyi.biz.model.resp.BizReceiptResp;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.biz.domain.BizReceipt;
import com.ruoyi.biz.service.BizReceiptService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 收款登记Controller
 * 
 * @author tianl
 * @date 2025-01-01
 */
@RestController
@RequestMapping("/biz/bizReceipt")
public class BizReceiptController extends BaseController {
    @Autowired
    private BizReceiptService bizReceiptService;

    @GetMapping(value = "/getSurplus")
    public AjaxResult getSurplus(Long projectId) {
        return success(bizReceiptService.surplus(projectId));
    }


    /**
     * 收款登记全部列表
     */
    @GetMapping(value = "/listAll")
    public AjaxResult listAll(ReceiptProjectReq bizReceipt) {
        return success(bizReceiptService.list(bizReceipt));
    }

    /**
     * 查询收款登记列表
     */
    
    @GetMapping("/list")
    public TableDataInfo list(ReceiptProjectReq bizReceipt) {
        return getDataTable(bizReceiptService.listPage(bizReceipt));
    }

    /**
     * 导出收款登记列表
     */
    
    @Log(title = "收款登记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ReceiptProjectReq bizReceipt) {
        List<BizReceiptResp> list = bizReceiptService.list(bizReceipt);
        ExcelUtil<BizReceiptResp> util = new ExcelUtil<>(BizReceiptResp.class);
        util.exportExcel(response, list, "收款登记数据");
    }

    /**
     * 获取收款登记详细信息
     */
    
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(bizReceiptService.selectById(id));
    }

    /**
     * 新增收款登记
     */
    
    @Log(title = "收款登记", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizReceipt bizReceipt) {
        bizReceiptService.beforeSave(bizReceipt);
        return AjaxResult.success();
    }

    /**
     * 修改收款登记
     */
    
    @Log(title = "收款登记", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizReceipt bizReceipt) {
        bizReceiptService.beforeSave(bizReceipt);
        return AjaxResult.success();
    }

    /**
     * 删除收款登记
     */
    
    @Log(title = "收款登记", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        bizReceiptService.deleteByIds(ids);
        return AjaxResult.success();
    }
}
